<?php

class Cookies{
	
	var $context;
	function Cookies(&$context){
		$this->context = &$context;
		$this->_init();
	}
	
	function _init(){
	}
	
	function isExist($field=''){
		$this->init();
		if(isset($_COOKIE[$field])){
			return true;
		}
		return false;
	}
	
	function get($field=''){
		if($this->isExist($field)){
			return $_COOKIE[$field];
		}
		return false;
	}
	
	function update($field='',$value=''){
		if(!$this->isExist($field)){
			$this->create($field);
		}else{
			$_COOKIE[$field] = $value;
		}
	}
	
	function create($field='',$value='',$expire=3600,$path='',$domain='',$ssl=true){
		if($this->isExist($field)){
			//$this->caller->errorHandler->addWarning('Cannot create cookie called '.$field.' again.',__FILE__,__LINE__);
			return false;
		}
		@setcookie($field,$value,$expire,$path,$domain,$ssl);
		return true;
	}
	
	function remove($field=''){
		if(!$this->isExist($field)){
			//$this->context->errorHandler->addWarning('Cannot remove cookie called '.$field.'.',__FILE__,__LINE__);
			return false;
		}
		$value = $this->get($field);
		setcookie($field);
		unset($_COOKIE['field']);
		return $value;
	}
	
}

?>